﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="recObjectionDecisionsform.aspx.cs" Inherits="SIPO.Web.Forms.Transaction.ObjectionDecisionsform" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="<%= ResolveUrl("~/styles/example.css") %>" rel="stylesheet" type="text/css" />
    <link href="<%= ResolveUrl("~/styles/chosen/chosen.min.css") %>" rel="stylesheet" type="text/css" />

    <script src="<%= ResolveUrl("~/scripts/plupload/moxie.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/plupload/plupload.full.min.js") %>" type="text/javascript"></script>
    
    <script src="<%= ResolveUrl("~/scripts/helper.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.wrapper.js") %>" type="text/javascript"></script>   
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.inputmask.bundle.min.js") %>" type="text/javascript"></script>

</head>
 
<style type="text/css">
    .ui-autocomplete
    {
        max-height: 100px;
        overflow-y: auto; /* prevent horizontal scrollbar */
        overflow-x: hidden; /* add padding to account for vertical scrollbar */
        padding-right: 20px;
    }
    .custom-combobox
    {
        position: relative;
        display: inline-block;
    }
    .custom-combobox-toggle
    {
        position: absolute;
        top: 0;
        bottom: 0;
        margin-left: -1px;
        padding: 0; /* support: IE7 */
        height: 1.7em;
        top: 0.1em;
    }
    .custom-combobox-input
    {
        margin: 0;
        padding: 0.3em;
    }
    .style2
    {
        width: 154px;
    }
    .style6
    {
        width: 119px;
    }
    .style8
    {
        width: 10px;
    }
    .style9
    {
        width: 100px;
    }
    #filelist
    {
        width: 104px;
    }
    .style10
    {
        width: 126px;
    }
    </style>

    <script type="text/javascript">
        $("#txtNilai").inputmask("decimal", { radixPoint: ",", autoGroup: true, groupSeparator: ".", groupSize: 3, digits: 2, repeat: 18 });
        $("#btnSave").button({ icons: { primary: "ui-icon-disk"} });
        $("#btnClose").button({ icons: { primary: "ui-icon-close"} });
        $('#btnClose').click(function () {
            parent.$('#dialog').dialog("close");

            return false;
        });
</script>
<script type="text/javascript">

    var formUrl = '<%= ResolveUrl("~/forms/administration/sLogform.aspx") %>';

    $.validator.addMethod("regex", function (value, element, parameters) {
        var re = new RegExp(parameters);
        return re.test(value);
    });
        
</script>

<script type="text/javascript">

    $(document).ready(function () {


        $("#txtNoSuratKeputusan").upperCase();

        $("#txtNoSuratTanggapan").upperCase();

        var uploader = new plupload.Uploader({
            runtimes: 'html5,flash,silverlight',
            browse_button: 'pickfiles',
            container: 'container',
            max_file_size: '5mb',
            url: '<%= ResolveUrl("~/AjaxHandler/Transaction/recObjectionHandler.ashx") %>' + '?method=insertdecision ',
            flash_swf_url: '<%= ResolveUrl("~/scripts/plupload/Moxie.swf") %>',
            silverlight_xap_url: '<%= ResolveUrl("~/scripts/plupload/Moxie.xap") %>',
            filters: [
            { title: "Pdf files", extensions: "pdf" },
            { title: "Excel files", extensions: "xls, xlsx" },
			{ title: "Text files", extensions: "txt" },
			{ title: "Image files", extensions: "jpeg,jpg,gif,png" },
            { title: "Word files", extensions: "doc,docx" },
			{ title: "PowerPoint files", extensions: "ppt,pptx" }
		],
            resize: { width: 320, height: 240, quality: 90 }
        });

        uploader.bind('Init', function (up, params) {

            var msg = 'Untuk dapat melakukan proses unggah / upload dokumen, browser anda harus mendukung salah satu teknologi, HTML 5 / Flash / Silverlight';

            if (params.runtime == 'html5') {
                msg = '';
            } else if (params.runtime == 'flash') {
                msg = '';
            } else if (params.runtime == 'silverlight') {
                msg = ''
            }

            if (msg != '') {
                alert(msg);
            }

        });

        uploader.init();

        uploader.bind('FilesAdded', function (up, files) {

            if (up.files.length > 1) {
                alert('Hanya diperbolehkan satu file untuk di upload!');
                return false;
            }

            $.each(files, function (i, file) {
                $('#filelist').append(
                        '<div id="' + file.id + '">' +
                file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' + '</div>');
            });

            up.refresh(); // Reposition Flash/Silverlight
        });

        uploader.bind('FileUploaded', function (up, file, info) {

            var err = JSON.parse(info.response);
            alert(err.Message);

        });

        uploader.bind('Error', function (up, err) {
            $('#filelist').append("<div>Error: " + err.code +
			", Message: " + err.message + (err.file ? ", File: " + err.file.name : "") + "</div>");

            up.refresh(); // Reposition Flash/Silverlight

        });


        $("#txtNilai").inputmask("decimal", { radixPoint: ",", autoGroup: true, groupSeparator: ".", groupSize: 3, digits: 2, repeat: 18 });


        $("#txtTglSurat").datepicker({ showWeek: true, showButtonPanel: true,
            changeMonth: true, changeYear: true, dateFormat: 'dd/mm/yy',
            numberOfMonths: 1,
            onSelect: function (selected) {
                $("#txtTglTanggapan").datepicker("option", "mindate", selected)
            }
        });

        $("#txtTglTanggapan").datepicker({ showWeek: true, showButtonPanel: true,
            changeMonth: true, changeYear: true, dateFormat: 'dd/mm/yy',
            numberOfMonths: 1,
            onSelect: function (selected) {
                $("#txtTglSurat").datepicker("option", "mindate", selected)
            }
        });

        $("#txtNoSuratKeputusan").inputmask("Regex", { regex: "[0-9/ .-:A-Za-z()-]*" });

        $("#txtNoSuratTanggapan").inputmask("Regex", { regex: "[0-9/ .-:A-Za-z()-]*" });

        $("#txtTglSurat").inputmask("d/m/y", { "placeholder": "dd/mm/yyyy" });

        $("#txtTglTanggapan").inputmask("d/m/y", { "placeholder": "dd/mm/yyyy" });


        $("#hfTambah").val();

        //val untuk radio button
        $("#rbDitolak").click(function () {
            $("#hfRadio").val('Ditolak');
            $("#txtNilai").val($("#hfSanctionValue").val());
            $("#txtNilai").attr('disabled', 'disabled');
        });

        $("#rbDiterimaSebagian").click(function () {
            $("#hfRadio").val('Diterima Sebagian');
            $("#txtNilai").removeAttr('disabled');
            $("#txtNilai").val($("#hfDecisionValue").val());
            //$("#txtNilai").val('');
        });

        $("#rbDiterima").click(function () {
            $("#hfRadio").val('Diterima');
            $("#txtNilai").removeAttr('disabled');
            $("#txtNilai").val
            $("#txtNilai").val($("#hfDiterima").val());
        });

        var rules = {
            txtNoSuratKeputusan: "required",
            txtNoSurat: "required",
            txtTglSurat: "required",
            txtNilai: "required"
        };

        var messages = {
            txtNoSuratKeputusan: "No. Surat keputusan harus di isi",
            txtNoSurat: "No Surat harus di isi",
            txtTglSurat: "Tanggal harus di isi",
            txtNilai: "Nilai harus diisi"
        };

        //        $('#txtNoSuratKeputusan').change(function () {
        //            var objectionNo = $('#txtNoSuratKeputusan').val();

        //            var handlerUrl = '<%= ResolveUrl("~/ajaxhandler/Loaddata/validasidecisionno.ashx?DecisionNo=") %>';

        //            jQuery.ajax({
        //                type: 'POST',
        //                url: handlerUrl + objectionNo,
        //                contentType: 'application/json',
        //                dataType: 'json',
        //                success: function (data) {
        //                    if (data.jumlah > 0) {
        //                        alert("Nomor surat. sudah ada !");
        //                        $('#txtNoSuratKeputusan').val('');
        //                        $('#txtNoSuratKeputusan').focus();
        //                        $("#txtNoSuratKeputusan").css({ 'background-color': 'red' });
        //                    } else {
        //                        $("#txtNoSuratKeputusan").css({ 'background-color': 'white' });
        //                    }

        //                },
        //                error: function () {
        //                    alert('Error validasi no. S.K. !');
        //                }
        //            });
        //        });

        var validator = new jQueryValidatorWrapper("form1", rules, messages);



        $("#btnSave").click(function (e) {

            e.preventDefault();

            if (!validator.validate())
                return;

            var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recObjectionHandler.ashx") %>';
            var add = '<%= Request.Params["isedit"] %>';
            var no = '1';
            if (add == 0) {

                if (uploader.files.length > 0) // Insert with uploaded file.
                {
                    uploader.settings.multipart_params = {
                        'hfTambah': encodeURIComponent($('#hfTambah').val()),
                        'txtNoSuratKeputusan': encodeURIComponent($('#txtNoSuratKeputusan').val()),
                        'txtTglSurat': encodeURIComponent($('#txtTglSurat').val()),
                        'txtNoSuratTanggapan': encodeURIComponent($('#txtNoSuratTanggapan').val()),
                        'txtTglTanggapan': encodeURIComponent($('#txtTglTanggapan').val()),
                        'txtIdDebitur': encodeURIComponent($('#txtIdDebitur').val()),
                        'hfRadio': encodeURIComponent($('#hfRadio').val()),
                        'txtNilai': encodeURIComponent($('#txtNilai').val()),
                        'txtcatatan': encodeURIComponent($('#txtcatatan').val()),
                        'hfID': encodeURIComponent($('#hfID').val()),
                        'hfObjectionNo': encodeURIComponent($('#hfObjectionNo').val()),
                        'hfDebtorSectorId': encodeURIComponent($('#hfDebtorSectorId').val()),
                        'hfSanctionValue': encodeURIComponent($('#hfSanctionValue').val()),
                        'hfSanctionNo': encodeURIComponent($('#hfSanctionNo').val()),
                        'hfTransTypeId': encodeURIComponent($('#hfTransTypeId').val()),
                        'hfBillingNo': encodeURIComponent($('#hfBillingNo').val())
                    };
                    uploader.settings.url = handlerUrl + '?method=insertdecision';
                    uploader.start();
                }
                else {

                    $.post('<%= ResolveUrl("~/AjaxHandler/Transaction/recObjectionHandler.ashx") %>' + '?method=insertdecision',
                                $("#form1").serializeNoViewState())
                            .done(function (data) {
                                var r = JSON.parse(data);
                                alert(r.Message);
                            })
                            .fail(function () {
                                alert('Data gagal di tambah!');
                            });

                }

            }
            else {

                if (uploader.files.length > 0) // Update with uploaded file.
                {
                    uploader.settings.multipart_params = {
                        'txtNoSuratKeputusan': encodeURIComponent($('#txtNoSuratKeputusan').val()),
                        'txtTglSurat': encodeURIComponent($('#txtTglSurat').val()),
                        'txtNoSuratTanggapan': encodeURIComponent($('#txtNoSuratTanggapan').val()),
                        'txtTglTanggapan': encodeURIComponent($('#txtTglTanggapan').val()),
                        'txtIdDebitur': encodeURIComponent($('#txtIdDebitur').val()),
                        'hfRadio': encodeURIComponent($('#hfRadio').val()),
                        'txtNilai': encodeURIComponent($('#txtNilai').val()),
                        'txtcatatan': encodeURIComponent($('#txtcatatan').val()),
                        'hfID': encodeURIComponent($('#hfID').val()),
                        'hfObjectionNo': encodeURIComponent($('#hfObjectionNo').val()),
                        'hfSanctionValue': encodeURIComponent($('#hfSanctionValue').val()),
                        'hfSanctionNo': encodeURIComponent($('#hfSanctionNo').val()),
                        'hfTransTypeId': encodeURIComponent($('#hfTransTypeId').val())

                    };
                    uploader.settings.url = handlerUrl + '?method=insertdecision';
                    uploader.start();

                }
                else {

                    $.post('<%= ResolveUrl("~/AjaxHandler/Transaction/recObjectionHandler.ashx") %>' + '?method=insertdecision',
                                $("#form1").serializeNoViewState())
                            .done(function (data) {
                                var r = JSON.parse(data);
                                alert(r.Message);
                            })
                            .fail(function () {
                                alert('Data gagal di ubah!');
                            });

                }

            }

            parent.$('#dialog').dialog('close');

            setTimeout("parent.$('#table').trigger('reloadGrid');", 3000);

            return false;


        });

    });
</script>

<body>
    <form id="form1" runat="server">
    <div>
    
    <table border="0" style="width: 536px">
        <tr>
            <td class="style10">
                No.  
                Keputusan</td>
            <td class="style8">
                :
            </td>
            <td colspan="3"><asp:TextBox ID="txtNoSuratKeputusan" runat="server" Width="150" ></asp:TextBox>
                &nbsp;<span style="color: Red;">*</span>
            </td>
        </tr>
        <tr>
            <td class="style10">
                Tgl. Keputusan</td>
            <td class="style8">
                :
            </td>
            <td colspan="3">
                <asp:TextBox ID="txtTglSurat" runat="server" Width="100" ></asp:TextBox>&nbsp;<span style="color: Red;">*</span>
            </td>
        </tr>
        <tr>
            <td class="style10">
                No. Tanggapan </td>
            <td class="style8">
                :
            </td>
            <td colspan="3"><asp:TextBox ID="txtNoSuratTanggapan" runat="server" Width="150" ></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style10">
                Tgl. Tanggapan </td>
            <td class="style8">
                :
            </td>
            <td colspan="3">
                <asp:TextBox ID="txtTglTanggapan" runat="server" Width="100" ></asp:TextBox>
            </td>
        </tr>
        



       <tr>
            <td class="style10">
                Catatan
            </td>
            <td class="style8">
                :
            </td>
            <td colspan="3">
                <asp:TextBox ID="txtcatatan" TextMode="MultiLine" runat="server" Width="300" ></asp:TextBox>
            </td>
        </tr>

        <tr>
            <td class="style10">
                Keputusan
            </td>
            <td class="style8">
                :
            </td>
            <td class="style6">
                <asp:RadioButton ID="rbDiterima" runat="server" GroupName="a" />
                Diterima</td>
            <td class="style2">
                <asp:RadioButton ID="rbDiterimaSebagian" runat="server" GroupName="a" />
            Diterima Sebagian</td>
            <td class="style9">
                <asp:RadioButton ID="rbDitolak" runat="server" GroupName="a" />
            Ditolak</td>
            

        </tr>

        <tr>
            <td class="style10">
                Jumlah Pembayaran </td>
            <td class="style8">
                :
            </td>
            <td colspan="3">
                <asp:TextBox ID="txtNilai" runat="server" Width="200" MaxLength="100" ></asp:TextBox></td>
        </tr>
         <tr>
            <td class="style10">
                Lampiran</td>
            <td class="style8">
                :
            </td>
            <td class="style6">
                <div id="container">
                    <a id="pickfiles" class="plupload_button plupload_add ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
                        href="#"><span class="ui-button-icon-primary ui-icon ui-icon-circle-plus" /><span
                            class="ui-button-text">Add Files</span> </a>
                    <br />
                    <div id="filelist">
                </div>
            </td>
                &nbsp;
                
        </tr>

        <tr>
            <td colspan="2">
                &nbsp;
            </td>
            <td colspan="3">
                <asp:HiddenField ID="hfID" runat="server" />
                <asp:HiddenField ID="hfObjectionNo" runat="server" />
                <asp:HiddenField ID="hfDebtorSectorId" runat="server" />
                <asp:HiddenField ID="hfSanctionValue" runat="server" />
                <asp:HiddenField ID="hfSanctionNo" runat="server" />
                <asp:HiddenField ID="hfTransTypeId" runat="server" />
                <asp:HiddenField ID="hfRadio" runat="server" />
                <asp:HiddenField ID="hfDecisionValue" runat="server" />
                <asp:HiddenField ID="hfDiterima" runat="server" />
                <asp:HiddenField ID="hfTambah" runat="server" />
                <asp:HiddenField ID="hfBillingNo" runat="server" />
            </td>
            
        </tr>
        <tr>
            <td colspan="2">
                &nbsp;
            </td>
            <td colspan="3">
                <div style="text-align: right; padding-top: 10px;">
                    <button id="btnSave" type="button">
                        Simpan</button>
                    <button id="btnClose" type="button">
                        Batal</button>
                </div>
            </td>
        </tr>
    </table>

    </div>
    </form>
</body>
</html>
